import 'dart:async';

import 'package:flutter/material.dart';
import 'package:shopping_group/base/base_constant.dart';
import 'package:shopping_group/event/event.dart';
import 'package:shopping_group/modle/person/entity/userid_name_phone_entity.dart';
import 'package:shopping_group/res/colors.dart';
import 'package:shopping_group/utils/widget_utils.dart';

class UpTuanYouPage extends StatefulWidget {
  UpTuanYouPage({Key key}) : super(key: key);

  @override
  _UpTuanYouPageState createState() => _UpTuanYouPageState();
}

class _UpTuanYouPageState extends State<UpTuanYouPage>
    with AutomaticKeepAliveClientMixin {
  StreamSubscription _upSubscription;
  @override
  void initState() {
    super.initState();

    _upSubscription = eventBus.on<UpTuanyouListEvent>().listen((event) {
      setState(() {
        BaseConstant.uplistEntity = event.list;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
      ),
      child: _showlistView(),
    );
  }

  Widget _showlistView() {
    return ListView.builder(
      shrinkWrap: true,
      padding: const EdgeInsets.only(top: 4),
      itemCount: BaseConstant.uplistEntity.length,
      itemBuilder: buildItem,
    );
  }

  //ListView的Item
  Widget buildItem(BuildContext context, int index) {
    return Container(
      // margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
      child: _xunchaItem(BaseConstant.uplistEntity[index]),
    );
  }

  Widget _xunchaItem(UserIdNamePhoneEntity entity) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.transparent,
      ),
      alignment: FractionalOffset.centerLeft,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          SizedBox(
            height: 4,
          ),
          WidgetUtils.itmeStyleView(
              '${entity.name}\n\n${entity.phone}', entity.createDate,
              contentAlignment: Alignment.centerRight,
              textColor: Colours.gray_91,
              contentColor: Colours.gray_91),
          // SizedBox(
          //   height: 8,
          // ),
          // WidgetUtils.itmeStyleView(
          //     entity.actTypeName, '¥ ${entity.custAccountChgVal}',
          //     contentAlignment: Alignment.centerRight,
          //     isExpanded: false,
          //     isContentExpanded: true,
          //     contentColor: Colours.blackground_609,
          //     textColor: Colours.gray_91),
          SizedBox(
            height: 4,
          ),
          WidgetUtils.drawCodeDivider(height: 1),
        ],
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;

  @override
  void dispose() {
    _upSubscription?.cancel();
    super.dispose();
  }
}
